<?php

class Customfield {

    private $ID;
    private $wordpress_id;
    private $key;
    private $value;

    public function getByID($ID) {
        $list = array();
        $sql = "SELECT * FROM caws_customfields
                WHERE ID = '" . $ID . "' ";

        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['wordpress_id'] = $rows['wordpress_id'];
            $list[$i]['key'] = $rows['key'];
            $list[$i]['value'] = $rows['value'];
            $i++;
        }
        return $list;
    }

    public function getByObj(Customfield $c) {
        $list = array();
        $sql = "SELECT * FROM caws_customfields
                WHERE 1 ";

        if($c->getWordpressId() != NULL)  {
            $sql .= "AND wordpress_id = '" . $c->getWordpressId() . "' ";
        }

        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['wordpress_id'] = $rows['wordpress_id'];
            $list[$i]['key'] = $rows['key'];
            $list[$i]['value'] = $rows['value'];
            $i++;
        }
        return $list;
    }

    public function setID($ID) {
        $this->ID = $ID;
    }

    public function getID() {
        return $this->ID;
    }

    public function setWordpressId($wordpress_id) {
        $this->wordpress_id = $wordpress_id;
    }

    public function getWordpressId() {
        return $this->wordpress_id;
    }
}
?>
